import Ashily from "./Ashily.js";
import asynchronous from "./Asynchronous.js";
import Crops from "./Crops.js";
import keyprompt from "./KeyPrompt.js";
import Math from "./Math.js";
import CropsBehavior from "./crop_behaviors.js";


/**
 * 土地块
 */

const Plow = {

    update: function () {

        Plow.CalculatedDistance();
        Plow.DisplayInteractivePrompts();

    },

    onLayoutStart() {

        Plow.CurrentInteractivePlow = null;

    },




    async DisplayInteractivePrompts() {
		
		
        let InteractionDistance = 50

        for (let plow of rt.objects.f_plowBllock.instances()) {

            if (plow.instVars.DistanceFromPlayer <= InteractionDistance && plow.instVars.isFarm === 0) {

                keyprompt.showKeyPrompt(plow, plow.x - 40, plow.y - 80, "F键", "种植")
                plow.instVars.isInter = 1 // 正在互动
                Plow.CurrentInteractivePlow = plow  //当前互动的plow
                await asynchronous.waitTime(1000)
                keyprompt.RebackKeyPrompt()
                plow.instVars.isInter = 0  //取消正在互动
                Plow.CurrentInteractivePlow = null

            }

        }

    },



    CalculatedDistance() {
        for (let plow of rt.objects.f_plowBllock.instances()) {

            //console.log("hello")
            plow.instVars.DistanceFromPlayer = Math.GetDistance(plow.x, plow.y, Ashily.ashilyInstance.x, Ashily.ashilyInstance.y)
        }
    },





}

export default Plow;